<!DOCTYPE html>
<html>
<head>
	<title></title>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui-win.css" />
</head>
<style type="text/css">
	/****日报评论框开始*****/
	.win-daily{ width: 100%; height: 100%; opacity: 0;  -webkit-transition:all .3s;  transition:all .3s;  position: fixed; left: 0; right: 0; bottom: 0; }
	.win-daily.active{ opacity: 1; z-index: 10; }
	.win-daily .aui-content{ padding: 10px; position: fixed; left: 0; right: 0; bottom: 0; background-color: white; z-index: 2;  }
	.none {display:none;}
	#comment_textarea{height:5% ;font-size:0.9rem; background-color: #FFFFFF;}
	#reply_textarea{height:5% ;font-size:0.9rem; background-color: #FFFFFF;}
	/****日报评论框结束*****/
	
	.win-edit{ width: 100%; height: 100%; opacity: 0;  -webkit-transition:all .3s;  transition:all .3s;  position: fixed; left: 0; right: 0; bottom: 0; }
	.win-edit.active{ opacity: 1; z-index: 10; }
	.win-edit .aui-content{ padding: 10px; position: fixed; left: 0; right: 0; bottom: 0; background-color: white; z-index: 2;  }
	.none {display:none;}

    .win-reply{ width: 100%; height: 100%; opacity: 0;  -webkit-transition:all .3s;  transition:all .3s;  position: fixed; left: 0; right: 0; bottom: 0; }
    .win-reply.active{ opacity: 1; z-index: 10; }
    .win-reply .aui-content{ padding: 10px; position: fixed; left: 0; right: 0; bottom: 0; background-color: white; z-index: 2;  }
	
	/*	透明遮罩曾	*/
	.showdown{ position: fixed; left:0; top: 0; right: 0; bottom: 0; background-color: rgba(0,0,0,.6); }
	
	#textarea{
		height:15% ;font-size:1.0rem; background-color: #FFFFFF;
	}
    #textarea2{
        height:15% ;font-size:1.0rem; background-color: #FFFFFF;
    }

	.button_left{ float:left; font-size:0.9rem; margin-left:15px; margin-bottom:10px;}
	.button_right{ float:right; font-size:0.9rem; margin-right:15px; margin-bottom:10px;}
</style>
<body>
<!--日报评论框开-->
<div class="win-daily comment-frm none">
	<div  tapmode="hover" onclick="funCloseThisFrame();" class="showdown"></div>
	<div class="aui-content" style="background-color: #F5F5F5;">
    	<font  class="button_left" onclick="funCloseThisFrame()">取消</font>
    	<font  class="button_right" onclick="dailyComment()">发送</font>
        <div class="aui-list-item-input aui-margin-15" >
            <textarea id="comment_textarea" rows="3" style="border: 1px solid #C2C2C2" autofocus  placeholder="评论"></textarea>
        </div>
    </div>
</div>
<!--日报评论框结束--->
<!---日报回复框开始-->
<div class="win-daily comment-reply-frm none">
	<div  tapmode="hover" onclick="funCloseThisFrame();" class="showdown"></div>
	<div class="aui-content" style="background-color: #F5F5F5;">
    	<font  class="button_left" onclick="funCloseThisFrame()">取消</font>
    	<font  class="button_right" onclick="dailyReply()">发送</font>
        <div class="aui-list-item-input aui-margin-15" >
            <textarea id="reply_textarea" rows="3" style="border: 1px solid #C2C2C2" autofocus  placeholder="回复"></textarea>
        </div>
    </div>
</div>
<!---日报回复框结束-->
<!---文档评论框开始-->
<div class="win-edit edit-frm none">
<div  tapmode="hover" onclick="funCloseThisFrame();" class="showdown"></div>
	<div class="aui-content" style="background-color: #F5F5F5;">   
    	<font  class="button_left" onclick="funCloseThisFrame()">取消</font>
    	<font  class="button_right" onclick="funComment()">发送</font>
        <div class="aui-list-item-input aui-margin-15" >
            <textarea id="textarea" rows="4" style="border: 1px solid #C2C2C2" autofocus  placeholder="评论"></textarea>
        </div>
    </div>
</div>
<!---文档评论框结束-->
<!---文档回复框开始-->
<div class="win-reply reply-frm none">
    <div  tapmode="hover" onclick="funCloseThisFrame();" class="showdown"></div>
    <div class="aui-content" style="background-color: #F5F5F5;">   
        <font  class="button_left" onclick="funCloseThisFrame()">取消</font>
        <font  class="button_right" onclick="funAnswer()">发送</font>
        <div class="aui-list-item-input aui-margin-15" >
            <textarea id="textarea2" rows="4" style="border: 1px solid #C2C2C2" autofocus  placeholder=""></textarea>
        </div>
    </div>
</div>
<!---文档回复框结束-->
</body>
<script type="text/javascript" src="../script/zepto.min.js" ></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/aui-toast.js" ></script>
<script type="text/javascript">
	var toast = new auiToast();
	apiready = function(){
		//var frameName = $api.getStorage('backFrame');
		$api.addCls( $api.dom( '.'+api.frameName ), 'active' );
		$api.removeCls( $api.dom( '.'+api.frameName ), 'none' );
        $("#reply_textarea").attr('placeholder','回复'+api.pageParam.username+':');
		$("#textarea2").attr('placeholder','回复'+api.pageParam.user+':');
	};


	function funCloseThisFrame(){
		api.closeFrame();
		$api.rmStorage('backFrame');	//属于监听返回关闭页面所以当关闭本页时必须清除backFrame缓存变量
	}

	//提交日报评论
    function dailyComment( ){
        var comment = $api.dom('#comment_textarea').value;
        var username = $api.getStorage('username');
        if( ! $api.trimAll( comment ) ){
						toast.fail({
									title:"请输入评论",
									duration:2000
						});
            $api.dom('#comment_textarea').focus();
        }else{
            api.ajax({
                url : ServeUrl+'m=Daily&a=addComment',
                method : 'POST',
                cache : false,
                timeout : 30,
                dataType : 'json',
                data : {
                    values : {
                        daily_id: api.pageParam.daily_id,
                        comment:comment,
                        username:username,
                    }
                }
            }, function(ret, err) {
                if(ret.data.status == 1){
                    api.toast({
                        msg:'评论成功'
                    });

                		funCloseThisFrame();
                }
            });
        }
    }

		//提交日报回复
		function dailyReply( ){
				var comment = $api.dom('#reply_textarea').value;
				var username = $api.getStorage('username');
				if( ! $api.trimAll( comment ) ){
						toast.fail({
									title:"请输入评论",
									duration:2000
						});
						$api.dom('#comment_textarea').focus();
				}else{
						api.ajax({
								url : ServeUrl+'m=Daily&a=addReply',
								method : 'POST',
								cache : false,
								timeout : 30,
								dataType : 'json',
								data : {
										values : {
												daily_id: api.pageParam.daily_id,
												p_id: api.pageParam.id,
												receiveman: api.pageParam.username,
												comment:comment,
												username:username,
										}
								}
						}, function(ret, err) {
								if(ret.data.status == 1){
										api.toast({
												msg:'回复成功'
										});

										funCloseThisFrame();
								}
						});
				}
		}
		
		//提交文档评论
    function funComment( ){
        var comment = $api.dom('#textarea').value;
        if (!comment) {
            api.toast({
                msg:'请填写评论内容!'
            });
            return false;
        }
        // alert(api.pageParam.id);return fa
        var userid = $api.getStorage('username');
        if( ! $api.trimAll( comment ) ){
            $api.toast('请输入评论');
            $api.dom('#textarea').focus();
        }else{
            api.ajax({
                url : ServeUrl+'m=File&a=comment',
                method : 'POST',
                cache : false,
                timeout : 30,
                dataType : 'json',
                data : {
                    values : {
                        id: api.pageParam.id,
                        comment:comment,
                        userid:userid,
                    }
                }
            }, function(ret, err) {
                // alert(JSON.stringify(ret))
                if(ret.status == 1){
                    api.toast({
                        msg:'评论成功'
                    });
                    api.execScript({
                        name : 'file_detail',
                    	frameName: 'file_detail',
                        script: 'location.reload()'
                    });
                	/*toast.success({
	                    title:"评论成功",
	                    duration:2000
	                });*/	
                	funCloseThisFrame();
                }
            });
        }
    }

    //提交文档回复
    function funAnswer(){
        // return false;
        var comment = $api.dom('#textarea2').value;
        if (!comment) {
            api.toast({
                msg:'请填写回复内容!'
            });
            return false;
        }
        
        var userid = $api.getStorage('username');
       
        if( ! $api.trimAll( comment ) ){
            $api.toast('请输入回复');
            $api.dom('#textarea2').focus();
        }else{
            api.ajax({
                url : ServeUrl+'m=File&a=replyComment',
                method : 'POST',
                cache : false,
                timeout : 30,
                dataType : 'json',
                data : {
                    values : {
                        cid: api.pageParam.cid, //被回复评论的ID
                        faq: api.pageParam.id, // 文章id
                        comment:comment, // 回复内容
                        userid:userid, // 当前回复者
                    }
                }
            }, function(ret, err) {
                if(ret){
                    api.toast({
                        msg:'回复成功'
                    });
                    api.execScript({
                        name : 'file_detail',
                        frameName: 'file_detail',
                        script: 'location.reload()'
                    });
                    /*toast.success({
                        title:"评论成功",
                        duration:2000
                    });*/   
                    funCloseThisFrame();
                }
            });
        }
    }

</script>
</html>
